

	$.ajaxSetup({
	  	error: function (XMLHttpRequest, textStatus, errorThrown) {
			try{
				$.messager.progress('close');
			}catch(e){
				;
			}
			$.messager.alert("提示", "操作失败！", "error");
		},
		cache: false,
		complete: function(response, textStatus){
			if(typeof(response.status)!='undefined'){
				var sessionStatus = response.getResponseHeader("sessionstatus");
				var i=response.getAllResponseHeaders();
				if (typeof (sessionStatus) != "undefined" && sessionStatus != null) {
					$.messager.alert("提示","会话超时，请重新登录！", "warning", function(btn){
						var redirect = 'loginAdminOut.action';
						self.location = redirect;
						if(top.location!=self.location){
							top.location = redirect;
						}
					});
					return;
				}
			}
			if (response.success == 'error') {
				$.messager.alert("提示", "ERROR:系统异常,请联系系统管理员", "error");
				return;
			}
		}
	});

	/*if ($.fn.datagrid){
		$.fn.datagrid.defaults.onLoadError=function(){
			$.messager.alert("提示", "加载数据错误！", "error");
		};
	}*/		

/**
 * 
 */
$.extend($.fn.validatebox.defaults.rules, {   
	maxLength: {   
        validator: function(value, param){   
            return value.length <= param[0];   
        },   
        message: '最大长度{0}'  
	 },  
	 minLength: {   
        validator: function(value, param){   
            return value.length >= param[0];   
        },   
        message: '最小长度{0}'  
	 },  
    chinese: {   
        validator: function(value, param){   
        	var reg = /^[\a-\z\A-\Z0-9\u4E00-\u9FA5\_.]+$/i;
            return reg.test(value);
        },   
        message: '只能输入中文、英文、数字、_和.符号'  
    },
    number:{
    	validator: function(value, param){   
        	var reg = /^[0-9]+$/;
            return reg.test(value);
        },   
        message: '请输入数字' 
    },
    alpha_number: {  
    	validator: function(value, param){   
        	var reg = /^[a-zA-Z0-9]+$/;
            return reg.test(value);
        },   
        message: '请输入英文字母或数字' 
    },
    alphanum:{
    	validator: function(value, param){   
        	var reg = /\W/;
            return !(reg.test(value));
        },   
        message: '请输入英文字母,数字,下划线,其它字符是不允许的' 
    }, 
    mobilephone:{  
    	validator: function(value, param){ 
          	if(/(^[1][0-9]{10}$)/.test(value)) 
                  return true;  
            return false;  
    	},   
        message: '请输入正确的手机号码'  
    },
    equals: {   
        validator: function(value,param){  
            return value == $(param[0]).val();   
        },   
        message: '两次输入的密码不一致'  
    },
    maxdate:{
    	validator: function(value,param){  
    		var date = new Date();
    		var y = date.getFullYear();
    		var m = date.getMonth()+1;
    		var d = date.getDate();
    		var today = y+'-'+(m<10?('0'+m):m)+'-'+(d<10?('0'+d):d);
	     	if(value>today){
				return false;
	     	}else{
	     		return true;
	     	}
        },   
        message: '不能超过当前日期'  
    },
    datecheck:{
    	validator: function(value,param){ 
    		var end = $(param[0]).datebox('getValue');
    		var begin = value;
	     	if(begin>end){
				return false;
	     	}else{
	     		return true;
	     	}
        },   
        message: '开始日期不能大于结束日期'  
    },
    ip:{
    	validator: function(value,param){ 
    		var reg = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
    		return reg.test(value);
        },   
        message: '请输入正确的IP'  
    },
    mask:{
    	validator: function(value,param){ 
    		var reg = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
    		return reg.test(value);
        },   
        message: '请输入正确的子网掩码'  
    },
    dns:{
    	validator: function(value,param){ 
    		var reg = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
    		return reg.test(value);
        },   
        message: '请输入正确的DNS'  
    },
    gateway:{
    	validator: function(value,param){ 
    		var reg = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
    		return reg.test(value);
        },   
        message: '请输入正确的默认网关'  
    },
    year: {
    	validator: function(value,param){ 
    		var reg = /^([1-9][0-9]{3})$/;
    		return reg.test(value);
        },   
        message: '年份应为四位整数，如2012'  
    },
    month: {
    	validator: function(value,param){ 
    		var reg = /^(0[1-9]|1[0-2])$/;
    		return reg.test(value);
        },   
        message: '月份应为两位整数，如03'  
    },
    day: {
    	validator: function(value,param){ 
    		var reg = /^((0?[1-9])|((1|2)[0-9])|30|31)$/;
    		return reg.test(value);
        },   
        message: '日期应为两位整数，如04'  
    },
    fixDay: {
    	validator: function(value, param) {
    		return /([0-2][0-9])|(3[0-1])/.test(value);
    	},
    	message: '日期应为两位整数，如04，小于31'
    },
    hour: {
    	validator: function(value,param){ 
    		var reg = /^(0[0-9]|1[0-9]|2[0-3])$/;
    		return reg.test(value);
        },   
        message: '小时应为两位整数，如08'  
    },
    minute: {
    	validator: function(value,param){ 
    		var reg = /^([0-5][0-9])$/;
    		return reg.test(value);
        },   
        message: '分钟应为两位整数，如01'  
    },
    second: {
    	validator: function(value,param){ 
    		var reg = /^([0-5][0-9])$/;
    		return reg.test(value);
        },   
        message: '秒数应为两位整数，如09'  
    },
    webaddress:{
    	validator: function(value,param){ 
    		var reg = /^[a-zA-Z0-9_.]+$/i;
    		return reg.test(value);
        },   
        message: '请输入正确的时间服务器' 
    }
}); 

$.extend($.fn.datebox.defaults, {
	editable:false
});

$.extend($.fn.datebox.defaults, {
	formatter: function(date){
		var y = date.getFullYear();
		var m = date.getMonth() + 1;
		(m<10) && (m=('0' + m));
		var d = date.getDate();
		(d<10) && (d=('0' + d));
		return y + "-" + m + "-" + d;
	}
});

$.extend($.fn.progressbar.defaults, {
	text: "loading ..."
});
$.extend($.fn.panel.defaults, {
	cache: false,
	onMove: fixMove
});
/*修复窗口溢出其父容器时无法继续拖动BUG*/
function fixMove(leftPos, topPos) {
	if($.data(this, "fixMove") === true) {
		$.removeData(this, "fixMove");
		return;
	}
	var self = $(this).closest("div.panel");
	var doc = $(document);
	var thisWidth = self.width(), thisHeight = self.height();
	/*获取浏览器当前可视区域*/
	var _tmp = {width:0,height:0};
	if(window.innerHeight) {
		_tmp = {width:window.innerWidth, height:window.innerHeight};
	} else if(document.documentElement && document.documentElement.clientWidth) {
		_tmp = {width:document.documentElement.clientWidth, height:document.documentElement.clientHeight};
	}
	var totalWidth = _tmp.width, totalHeight = _tmp.height;
	if(leftPos < 0) {
		leftPos = 0;
	}
	if(leftPos + thisWidth >= totalWidth) {
		leftPos = totalWidth - thisWidth - 15;
	}
	if(topPos < 0) {
		topPos = 0;
	}
	if(topPos + thisHeight >= totalHeight) {
		topPos = totalHeight - thisHeight - 15;
	}
	var cache = $.data(this);
	$.data(this, "fixMove", true);
	if(cache.dialog) {
		$(this).dialog('move', {left:leftPos, top:topPos});
	} else if(cache.window) {
		$(this).window('move', {left:leftPos, top:topPos});
	} else if(cache.panel) {
		$(this).panel('move', {left:leftPos, top:topPos});
	}
}

setTimeout(function(){
	$(".easyui-window,.easyui-dialog").each(function(){
		var p = $.data(this, "panel");
		p.options.onMove = fixMove;
	});
}, 300);